package summer.backtracking;

import java.util.ArrayList;
import java.util.List;

public class Solution17 {
    List<String> res = new ArrayList<>();
    String[] numString = {"", "", "abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
    StringBuffer sb = new StringBuffer();

    public List<String> letterCombinations(String digits) {
        if (digits == null || digits.isEmpty()) return res;
        backtracking(digits, 0);
        return res;
    }

    public void backtracking(String digits, int index) {
        if (index == digits.length()) {
            res.add(sb.toString());
            return;
        }
        String curStr = numString[digits.charAt(index) - '0'];
        for (int i = 0; i < curStr.length(); i++) {
            sb.append(curStr.charAt(i));
            backtracking(digits, index + 1);
            sb.deleteCharAt(sb.length() - 1);
        }

    }
}
